﻿using System;
using System.Collections.Generic;
using UnityEngine;

// Token: 0x02000421 RID: 1057
public class LightColorDebug : MonoBehaviour
{
	// Token: 0x06001A33 RID: 6707 RVA: 0x000A7A50 File Offset: 0x000A5C50
	public void Load()
	{
		ListDataLoader listDataLoader = new ListDataLoader('\t', StringSplitOptions.None);
		listDataLoader.Load_Text(this.mapLightColorText, -1, -1);
		for (int i = 0; i < listDataLoader.Y_Num; i++)
		{
			string text = listDataLoader.Get(0, i);
			if (text.Length > 0)
			{
				LightColorDebug.MapLight item = new LightColorDebug.MapLight(listDataLoader, i);
				this.mapLights.Add(item);
			}
		}
	}

	// Token: 0x06001A34 RID: 6708 RVA: 0x000A7AB8 File Offset: 0x000A5CB8
	public void SetToMap(int mapNo, int timeNo, Transform mapRoot)
	{
		this.mapLights[mapNo].Set(mapRoot, timeNo);
	}

	// Token: 0x04001D14 RID: 7444
	[SerializeField]
	private TextAsset mapLightColorText;

	// Token: 0x04001D15 RID: 7445
	private List<LightColorDebug.MapLight> mapLights = new List<LightColorDebug.MapLight>();

	// Token: 0x02000422 RID: 1058
	public class MapLight
	{
		// Token: 0x06001A35 RID: 6709 RVA: 0x000A7AD0 File Offset: 0x000A5CD0
		public MapLight(ListDataLoader loader, int y)
		{
			this.name = loader.Get(0, y);
			for (int i = 0; i < this.timeZones.Length; i++)
			{
				int x = 2 + 3 * i;
				this.timeZones[i] = new LightColorDebug.MapLight.TimeZone(loader, x, y);
			}
		}

		// Token: 0x06001A36 RID: 6710 RVA: 0x000A7B2C File Offset: 0x000A5D2C
		public void Set(Transform mapRoot, int timeNo)
		{
			this.timeZones[timeNo].Set(mapRoot);
		}

		// Token: 0x04001D16 RID: 7446
		private LightColorDebug.MapLight.TimeZone[] timeZones = new LightColorDebug.MapLight.TimeZone[4];

		// Token: 0x04001D17 RID: 7447
		public string name;

		// Token: 0x02000423 RID: 1059
		private class LightSet
		{
			// Token: 0x06001A37 RID: 6711 RVA: 0x000A7B3C File Offset: 0x000A5D3C
			public LightSet(ListDataLoader loader, int x, int y)
			{
				this.name = loader.Get(x, y);
				float h = loader.GetFloat(x, y + 1) / 359f;
				float s = loader.GetFloat(x, y + 2) / 255f;
				float v = loader.GetFloat(x, y + 3) / 255f;
				this.color = Color.HSVToRGB(h, s, v);
				this.intensity = loader.GetFloat(x, y + 4);
			}

			// Token: 0x04001D18 RID: 7448
			public string name;

			// Token: 0x04001D19 RID: 7449
			public Color color;

			// Token: 0x04001D1A RID: 7450
			public float intensity = 1f;
		}

		// Token: 0x02000424 RID: 1060
		private class TimeZone
		{
			// Token: 0x06001A38 RID: 6712 RVA: 0x000A7BBC File Offset: 0x000A5DBC
			public TimeZone(ListDataLoader loader, int x, int y)
			{
				this.lights[0] = new LightColorDebug.MapLight.LightSet(loader, x, y);
				this.lights[1] = new LightColorDebug.MapLight.LightSet(loader, x + 1, y);
				this.ambient = loader.GetFloat(x, y + 5);
			}

			// Token: 0x06001A39 RID: 6713 RVA: 0x000A7C18 File Offset: 0x000A5E18
			public void Set(Transform mapRoot)
			{
				int num = 0;
				Light[] componentsInChildren = mapRoot.GetComponentsInChildren<Light>();
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if (componentsInChildren[i].name == this.lights[0].name)
					{
						this.SetLight(componentsInChildren[i], this.lights[0]);
						num |= 1;
					}
					else if (componentsInChildren[i].name == this.lights[1].name)
					{
						this.SetLight(componentsInChildren[i], this.lights[1]);
						num |= 2;
					}
				}
				if ((num & 1) == 0)
				{
					GlobalData.Debug_LogWarning("光线:" + this.lights[0].name + "却没有找到");
				}
				if ((num & 2) == 0)
				{
					GlobalData.Debug_LogWarning("光线:" + this.lights[1].name + "却没有找到");
				}
				if (RenderSettings.ambientIntensity != this.ambient)
				{
					RenderSettings.ambientIntensity = this.ambient;
					GlobalData.Debug_Log("环境变更");
				}
			}

			// Token: 0x06001A3A RID: 6714 RVA: 0x000A7D28 File Offset: 0x000A5F28
			private void SetLight(Light light, LightColorDebug.MapLight.LightSet set)
			{
				if (light.color != set.color || light.intensity != set.intensity)
				{
					GlobalData.Debug_Log("浅颜色变更");
				}
				light.color = set.color;
				light.intensity = set.intensity;
				AlloyAreaLight component = light.GetComponent<AlloyAreaLight>();
				if (component != null)
				{
					component.Color = set.color;
					component.Intensity = set.intensity;
				}
			}

			// Token: 0x04001D1B RID: 7451
			public LightColorDebug.MapLight.LightSet[] lights = new LightColorDebug.MapLight.LightSet[2];

			// Token: 0x04001D1C RID: 7452
			public float ambient = 1f;
		}
	}
}
